package cn.broadin.app.hotel.util;

import cn.broadin.app.hotel.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 显示自定义消息
 * 
 * @author long
 * @version 1.0.0
 * @date 2015年10月20日下午7:08:36
 */
@SuppressLint("InflateParams")
public class XToast extends Toast {

	private ImageView img;
	private TextView tv;
	private Context context;

	public XToast(Context context) {
		super(context);

		this.context = context;
		View view = LayoutInflater.from(context).inflate(R.layout.itv_toast, null);
		img = view.findViewById(R.id.itv_toast_img);
		tv = view.findViewById(R.id.itv_toast_text);
		setView(view);
	}
	
	public void setTextSize(float size) {
		tv.setTextSize(size);
	}

	public void setTextColor(int colorRes) {
		tv.setTextColor(context.getResources().getColor(colorRes));
	}

	public void setIcon(int imgRes) {
		img.setImageResource(imgRes);
	}

	public void setIcon(Drawable imgDr) {
		img.setImageDrawable(imgDr);
	}

	public void removeIcon() {
		img.setImageBitmap(null);
	}

	public void setText(String msg) {
		tv.setText(msg);
	}

	public void setText(int stringRes) {
		tv.setText(stringRes);
		// Toast.makeText(context, text, duration)
	}
	
	public static XToast makeText(Context context, String text) {
		XToast toast = new XToast(context);
		toast.setText(text);
		toast.setDuration(Toast.LENGTH_LONG);
		return toast;
	}

	public static XToast makeText(Context context, String text, int duration) {
		XToast toast = new XToast(context);
		toast.setText(text);
		toast.setDuration(duration);
		return toast;
	}

	public static XToast makeText(Context context, int textRes, int duration) {
		XToast toast = new XToast(context);
		toast.setText(textRes);
		toast.setDuration(duration);
		return toast;
	}

	public static XToast makeText(Context context, int textRes, int duration,
			int imgRes) {
		XToast toast = new XToast(context);
		toast.setText(textRes);
		toast.setDuration(duration);
		toast.setIcon(imgRes);
		return toast;
	}

	public static XToast makeText(Context context, int textRes, int duration,
			Drawable imgDr) {
		XToast toast = new XToast(context);
		toast.setText(textRes);
		toast.setDuration(duration);
		toast.setIcon(imgDr);
		return toast;
	}

	public static XToast makeText(Context context, String text, int duration,
			Drawable imgDr) {
		XToast toast = new XToast(context);
		toast.setText(text);
		toast.setDuration(duration);
		toast.setIcon(imgDr);
		return toast;
	}

}
